"""
File: tag.py
Author: ershixiong
Date: 2023/12/12
describe:

"""
from jsonpath import jsonpath

from project202311_wework.wework.frame.apis.wework import Wework


class Tag(Wework):
    def create(self, data):
        url = 'tag/create'

        req = {
            'method': 'POST',
            'url': url,
            'json': data
        }

        r = self.send_api(req)
        return r

    def update(self, data):
        url = 'tag/update'

        req = {
            'method': 'POST',
            'url': url,
            'json': data
        }

        r = self.send_api(req)
        return r

    def list(self):
        url = 'tag/list'

        req = {
            'method': 'POST',
            'url': url,
        }

        r = self.send_api(req)
        return r

    def delete(self, tagid):
        url = 'tag/delete'
        params = {
            'tagid': tagid
        }

        req = {
            'method': 'POST',
            'url': url,
            'params': params
        }

        r = self.send_api(req)
        return r

    def clear(self):
        r = self.list()
        taglist = jsonpath(r.json(), '$..taglist')[0]
        if len(taglist) > 0:
            for tag in taglist:
                self.delete(tag.get('tagid'))

    def tag_member_add(self, data):
        url = 'tag/addtagusers'

        req = {
            'method': 'POST',
            'url': url,
            'json': data
        }

        r = self.send_api(req)
        return r

    def tag_member_list(self, tagid):
        url = 'tag/get'
        params = {
            'tagid': tagid
        }

        req = {
            'method': 'POST',
            'url': url,
            'params': params
        }

        r = self.send_api(req)
        return r

    def tag_member_delete(self, data):
        url = 'tag/deltagusers'

        req = {
            'method': 'POST',
            'url': url,
            'json': data
        }

        r = self.send_api(req)
        return r
